﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace AbpCompanyName.AbpProjectName.Migrations;

public partial class Upgraded_To_Abp_5_4_0 : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropIndex(
            name: "IX_AbpOrganizationUnits_TenantId_Code",
            table: "AbpOrganizationUnits");

        migrationBuilder.CreateTable(
            name: "AbpDynamicParameters",
            columns: table => new
            {
                Id = table.Column<int>(nullable: false)
                    .Annotation("SqlServer:Identity", "1, 1"),
                ParameterName = table.Column<string>(nullable: true),
                InputType = table.Column<string>(nullable: true),
                Permission = table.Column<string>(nullable: true),
                TenantId = table.Column<int>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpDynamicParameters", x => x.Id);
            });

        migrationBuilder.CreateTable(
            name: "AbpDynamicParameterValues",
            columns: table => new
            {
                Id = table.Column<int>(nullable: false)
                    .Annotation("SqlServer:Identity", "1, 1"),
                Value = table.Column<string>(nullable: false),
                TenantId = table.Column<int>(nullable: true),
                DynamicParameterId = table.Column<int>(nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpDynamicParameterValues", x => x.Id);
                table.ForeignKey(
                    name: "FK_AbpDynamicParameterValues_AbpDynamicParameters_DynamicParameterId",
                    column: x => x.DynamicParameterId,
                    principalTable: "AbpDynamicParameters",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateTable(
            name: "AbpEntityDynamicParameters",
            columns: table => new
            {
                Id = table.Column<int>(nullable: false)
                    .Annotation("SqlServer:Identity", "1, 1"),
                EntityFullName = table.Column<string>(nullable: true),
                DynamicParameterId = table.Column<int>(nullable: false),
                TenantId = table.Column<int>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpEntityDynamicParameters", x => x.Id);
                table.ForeignKey(
                    name: "FK_AbpEntityDynamicParameters_AbpDynamicParameters_DynamicParameterId",
                    column: x => x.DynamicParameterId,
                    principalTable: "AbpDynamicParameters",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateTable(
            name: "AbpEntityDynamicParameterValues",
            columns: table => new
            {
                Id = table.Column<int>(nullable: false)
                    .Annotation("SqlServer:Identity", "1, 1"),
                Value = table.Column<string>(nullable: false),
                EntityId = table.Column<string>(nullable: true),
                EntityDynamicParameterId = table.Column<int>(nullable: false),
                TenantId = table.Column<int>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpEntityDynamicParameterValues", x => x.Id);
                table.ForeignKey(
                    name: "FK_AbpEntityDynamicParameterValues_AbpEntityDynamicParameters_EntityDynamicParameterId",
                    column: x => x.EntityDynamicParameterId,
                    principalTable: "AbpEntityDynamicParameters",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateIndex(
            name: "IX_AbpOrganizationUnits_TenantId_Code",
            table: "AbpOrganizationUnits",
            columns: new[] { "TenantId", "Code" },
            unique: true,
            filter: "[TenantId] IS NOT NULL");

        migrationBuilder.CreateIndex(
            name: "IX_AbpDynamicParameters_ParameterName_TenantId",
            table: "AbpDynamicParameters",
            columns: new[] { "ParameterName", "TenantId" },
            unique: true,
            filter: "[ParameterName] IS NOT NULL AND [TenantId] IS NOT NULL");

        migrationBuilder.CreateIndex(
            name: "IX_AbpDynamicParameterValues_DynamicParameterId",
            table: "AbpDynamicParameterValues",
            column: "DynamicParameterId");

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityDynamicParameters_DynamicParameterId",
            table: "AbpEntityDynamicParameters",
            column: "DynamicParameterId");

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityDynamicParameters_EntityFullName_DynamicParameterId_TenantId",
            table: "AbpEntityDynamicParameters",
            columns: new[] { "EntityFullName", "DynamicParameterId", "TenantId" },
            unique: true,
            filter: "[EntityFullName] IS NOT NULL AND [TenantId] IS NOT NULL");

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityDynamicParameterValues_EntityDynamicParameterId",
            table: "AbpEntityDynamicParameterValues",
            column: "EntityDynamicParameterId");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropTable(
            name: "AbpDynamicParameterValues");

        migrationBuilder.DropTable(
            name: "AbpEntityDynamicParameterValues");

        migrationBuilder.DropTable(
            name: "AbpEntityDynamicParameters");

        migrationBuilder.DropTable(
            name: "AbpDynamicParameters");

        migrationBuilder.DropIndex(
            name: "IX_AbpOrganizationUnits_TenantId_Code",
            table: "AbpOrganizationUnits");

        migrationBuilder.CreateIndex(
            name: "IX_AbpOrganizationUnits_TenantId_Code",
            table: "AbpOrganizationUnits",
            columns: new[] { "TenantId", "Code" });
    }
}
